#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkLight.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkSphereSource.h>

#include <array>

int main()
{
    vtkNew<vtkNamedColors> colors;
    std::array<unsigned char, 4> bkg{{26, 51, 102, 255}};

    vtkNew<vtkSphereSource> sphere;
    sphere->SetThetaResolution(100);
    sphere->SetPhiResolution(50);

    vtkNew<vtkPolyDataMapper> sphereMapper;
    sphereMapper->SetInputConnection(sphere->GetOutputPort());

    //1个 mapper 对应多个 actor
    auto const numberOfSpheres = 8;
    std::array<vtkNew<vtkActor>, numberOfSpheres> spheres;
    auto ambient = 0.125;
    auto diffuse = 0.0;
    auto specular = 0.0;
    std::array<double, 3> position{{0, 0, 0}};
    for (int i = 0; i < spheres.size(); ++i)
    {
        spheres[i]->SetMapper(sphereMapper);
        spheres[i]->GetProperty()->SetColor(colors->GetColor3d("Red").GetData());
        spheres[i]->GetProperty()->SetAmbient(ambient);
        spheres[i]->GetProperty()->SetDiffuse(diffuse);
        spheres[i]->GetProperty()->SetSpecular(specular);
        spheres[i]->AddPosition(position.data());
        ambient += 0.125;
        position[0] += 1.25;
        if(i == 3)
        {
            position[0] = 0;
            position[1] = 1.25;
        }
    }

    //创建render 和 renderwindow + 交互
    vtkNew<vtkRenderer>ren;
    vtkNew<vtkRenderWindow>renWin;
    renWin->AddRenderer(ren);
    vtkNew<vtkRenderWindowInteractor>iren;
    iren->SetRenderWindow(renWin);

    //每一个actor都放入一个渲染器
    for(int i = 0; i < numberOfSpheres;++i)
    {
        ren->AddActor(spheres[i]);
    }

    ren->SetBackground(colors->GetColor3d("bkg").GetData());
    renWin->SetSize(640,480);
    std:cout<<"DPI:"<<renWin->GetDPI()<<std::endl;
    renWin->SetWindowName("Ambientpheres");

    // vtkNew<vtkLight>light;
    // light->SetFocalPoint(1.875,0.6125,0);
    // light->SetPosition(0.875,1.6125,1);
    // ren->AddLight(light);

    // ren->GetActiveCamera()->SetFocalPoint(0,0,0);
    // ren->GetActiveCamera()->SetPosition(0,0,1);
    // ren->GetActiveCamera()->SetViewUp(0,1,0);
    // ren->ResetCamera();
    // ren->GetActiveCamera()->SetParallelProjection(2.0);

    iren->Initialize();
    renWin->Render();
    iren->Start();


    return 0;
}